package main

import (
	"fmt"
	"math/rand"
	"time"
)

func main(){
	//yanZheng()
	//sum_rectangle()
	name_system()
}

/*
练习4：验证用户名密码是否正确
var userList = map[string]map[string]string{
	"root":{"password":"123456", "tel":"158xxxxxxxx"},
	"admin":{"password":"123456", "tel":"137xxxxxxxx"},
	"xiaoming":{"password":"123456", "tel":"199xxxxxxxx"}}
输入用户名密码，进行验证，验证成功后，输出手机号码
 */
func yanZheng(){
	var userList1 = map[string]map[string]string{
		"root":{"password":"123456", "tel":"158xxxxxxxx"},
		"admin":{"password":"123456", "tel":"137xxxxxxxx"},
		"xiaoming":{"password":"123456", "tel":"199xxxxxx"}}
	fmt.Print("请输入用户名：")
	var username string
	fmt.Scan(&username)
	fmt.Print("请输入密码:")
	var password string
	fmt.Scan(&password)
	for key,value:=range userList1{
		if key==username && value["password"]==password{
			fmt.Println(value["tel"])
			break
		}
	}
}

/*
练习2：求两个3*3矩阵的和并输出（数据都是int类型）
	解析：矩阵的和计算规则是对应元素相加：
	c[i][j] = a[i][j] + b[i][j]
 */
func sum_rectangle(){
	var arr1 = [3][3]int{{1,2,3},{3,4,5},{6,7,8}}
	var arr2 = [3][3]int{{4,6,7},{7,4,5},{3,5,7}}
	var arr3 [3][3]int
	for i:=0;i<len(arr1);i++{
		for j:=0;j<3;j++{
			arr3[i][j]=arr1[i][j]+arr2[i][j]
		}
	}
	fmt.Println(arr3)
}

/*
练习3：使用go编写随机点名系统
	切片类型存放全班同学的名字：["史伟名","易鸽玲"]
	按任意键，不限次数随机抽取切片中的某一个同学名字回答问题
			 抽取到的同学就从切片中删除
	按q退出，或者切片里面所有的同学都已近被抽到
 */
func name_system(){
	name_class := []string{"qy","ysj","xjw","zyq","wbw","cty","frx"}
	rand.Seed(time.Now().UnixNano())
	for true{
		fmt.Print("按任意键进行，按q退出：")
		var option string
		var num int
		fmt.Scan(&option)
		if option=="q" || len(name_class)==0{
			if len(name_class)==0{
				fmt.Println("全部名字都被抽取！")
			}
			break
		}
		num=rand.Intn(len(name_class))
		fmt.Println(name_class[num])
		name_class = append(name_class[:num],name_class[num+1:]...)
	}
}